<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2024/12/24 0024
  Time: 14:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>生产派工单审核子页面</title>
    <link rel="stylesheet"  href="/bootstrap/bootstrap-5.3.3-dist/css/bootstrap.min.css" />
    <link rel="stylesheet" href="/css/manufactureCss/e/production_dispatch_order_review_sub.css"></link>
    <style type="text/css">

    </style>
</head>
<body style="padding: 15px 50px;background-color: #eeeeee;">
<div class="panel-heading hhead">
    <nav aria-label="breadcrumb">
        <ol class="breadcrumb">
            <span style="color: blue;">您正在做的业务是：</span>
            <li class="breadcrumb-item"><a href="#">生产管理</a></li>
            <li class="breadcrumb-item"><a href="#">生产调度管理</a></li>
            <li class="breadcrumb-item active" aria-current="page">生产派工单审核</li>
        </ol>
    </nav>
</div>
<div style="margin-bottom: 2px">
    <div style="display: inline;margin-left: 78%;">
        <input type="radio" name="checkTag" value="2"/>未通过
        <input type="radio" name="checkTag" value="1"/>通过
        <button class="btn btn-primary" id="submit">提交</button>
<%--        <button class="btn btn-primary">返回</button>--%>
    </div>
</div> <!-- 此div改用栅格来做 -->
<div id="designListBox">
    <div style="text-align: center">
        <h3>生产派工单</h3>
    </div>
    <div style="padding: 30px">
        <table class="tbl1">
            <tr>
                <td class="col1">派工单编号：</td>
                <td colspan="2" id="manufactureId"></td>
            </tr>
            <tr>
                <td class="col1">产品编号：</td>
                <td class="col2" id="productId"></td>
                <td class="col1">产品名称：</td>
                <td class="col2" id="productName"></td>
            </tr>
            <tr>
                <td class="col1">数量：</td>
                <td class="col2" id="amount"></td>
                <td class="col1">工单制定人：</td>
                <td class="col2" id="designer"></td>
            </tr>
        </table>

        <table class="table table-bordered" style="margin: 15px auto;">
            <thead>
            <tr>
                <th>序号</th><th width="85px">工序名称</th><th width="85px">工序编号</th>
                <th width="380px">描述</th><th width="110px">工时数(小时)</th><th width="150px">工时成本小计(元)</th>
                <th width="120px">物料成本小计</th><th>详情</th>
            </tr>
            </thead>
            <tbody id="template">

            </tbody>
            </tbody>
        </table>

        <table class="tbl3">
            <tr>
                <td class="col1">工时总成本：</td>
                <td colspan="1" id="labourCostPriceSum"></td>
                <td class="col1">物料总成本：</td>
                <td colspan="2" id="moduleCostPriceSum"></td>
            </tr>
            <tr>
                <td class="col1">登记人：</td>
                <td colspan="1" id="register"></td>
                <td class="col1">登记时间：</td>
                <td colspan="2" id="registerTime"></td>
            </tr>
            <tr>
                <td class="col1">审核人：</td>
                <td colspan="1"><input type="text" class="txt_under_line" id="checker"></td>
                <td class="col1">审核时间：</td>
                <td colspan="2" id="checkTime"></td>
            </tr>
            <tr>
                <td class="col1">描述：</td>
                <td colspan="1"></td>
                <td class="col1">出库单编号：</td>
                <td colspan="2"></td>
            </tr>
            <tr>
                <td class="col1">备注：</td>
                <td colspan="3" style="padding-top: 5px">
                    <textarea rows="4" cols="100" id="remark"></textarea>
                </td>
            </tr>
        </table>
    </div>
</div>
<div class="modal fade" id="AddProductProcessMaterialModal" data-bs-backdrop="static" data-bs-keyboard="false" tabindex="-1" aria-labelledby="staticBackdropLabel" aria-hidden="true">
    <div class="modal-dialog modal-xl">
        <div class="modal-content" style="height: 450px">
            <div class="modal-header" style="height: 8%">
                <h3 class="modal-title" id="staticBackdropLabel">查看物料</h3>
                <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
            </div>
            <div class="modal-body" style="height: 100%;width: 100%;margin: -1%">
                <iframe id="iframe2" src="" style="width: 100%;height: 99%"></iframe>
            </div>
            <div class="modal-footer" style="height: 15%">
                <button id="btnConcel" class="btn btn-success" data-bs-dismiss="modal">
                    确认<span class="glyphicon glyphicon-remove"></span>
                </button>
            </div>
        </div>
    </div>
</div>


<script type="text/javascript" src="/js/jquery-3.7.0.min.js"></script>
<script type="text/javascript" src="/bootstrap/bootstrap-5.3.3-dist/js/bootstrap.bundle.js"></script>
<script type="text/javascript">
    $(function () {
        // 初始化时间
        setInterval(updateDateTime, 1000);

        initialTable()

        $("#submit").click(function () {
            let id = sessionStorage.getItem("id");
            let checkTag = $("input[name='checkTag']:checked").val();
            let checker = $("#checker").val();
            if (checker === "") {
                alert("请输入审核人")
                return;
            }
            //判断是否选择了审核结果
            if (checkTag === undefined || checkTag === ""||checkTag === null) {
                alert("请选择审核结果")
                return;
            }
            let data = {
                id:id,
                checkTag:checkTag,
                checker:checker
            }
            //判断是否已经提交，如果已经提交，不能再提交
            let submitTag = sessionStorage.getItem("submitTag");
            if (submitTag === "1") {
                alert("已经提交，不能再提交")
                return;
            }
            //存储提交标识,提交后不能再提交
            sessionStorage.setItem("submitTag",1);
            //存储到sessionStorage
            sessionStorage.setItem("data",JSON.stringify(data));
            alert("提交成功")
        })
    })
    function initialTable() {
        let id = sessionStorage.getItem("id");
        $.ajax({
            url:"/m-manufacture/selectById?id="+id,
            type:"get",
            dataType:"json",
            success:function (mManufacture) {
                $("#manufactureId").text(mManufacture.manufactureId);
                $("#productId").text(mManufacture.productId);
                $("#productName").text(mManufacture.productName);
                $("#amount").text(mManufacture.amount);
                $("#designer").text(mManufacture.designer);
                $("#labourCostPriceSum").text(mManufacture.labourCostPriceSum);
                $("#moduleCostPriceSum").text(mManufacture.moduleCostPriceSum);
                $("#register").text(mManufacture.register);
                $("#registerTime").text(mManufacture.registerTime);
                $("#remark").text(mManufacture.remark);
                initialTemplate(id);
            }

        })
    }
    function initialTemplate(id) {
        $.ajax({
            type: "GET",
            url: "/m-procedure/selectArrByParentId?id="+id,
            dataType: "json",
            success: function (data){
                console.log(data);
                $("#template").empty()

                for (let i = 0; i < data.length; i++) {
                    let moduleSubtotal = 0;
                    data[i].moduleSubtotal === null ? moduleSubtotal = 0 : moduleSubtotal = data[i].moduleSubtotal;
                    let procedureDescribe = data[i].procedureDescribe != undefined?data[i].procedureDescribe:""
                    let tr = "<tr>" +
                        "<td class='ckbox' id='"+data[i].procedureId+"'>"+(i+1)+"</td>" +
                        "<td>"+data[i].procedureName+"</td>" +
                        "<td>"+data[i].procedureId+"</td>" +
                        "<td>"+procedureDescribe+"</td>" +
                        "<td class='num'>"+data[i].labourHourAmount+"</td>" +
                        "<td class='num'>"+data[i].subtotal+"</td>" +
                        "<td class='num'>"+moduleSubtotal+"</td>" +
                        '<td><a href="javascript:select('+'\''+data[i].id+'\''+','+'\''+data[i].procedureName+'\''+')" class="btn btn-outline-success">查看</a></td>' +
                        "</tr>";
                    $("#template").append(tr);
                }
            }
        })
    }
    function select(id,procedureName) {
        sessionStorage.setItem("id",id);
        let manufactureId = $("#manufactureId").text()
        sessionStorage.setItem("manufactureId",manufactureId);
        sessionStorage.setItem("procedureName",procedureName);
        $("#AddProductProcessMaterialModal").modal("show");
        $("#iframe2").attr("src","/m-procedure-module/MProcedureModuleListReviewSub");
    }
    function updateDateTime(){
        let date = new Date();
        let year = date.getFullYear();
        let month = (date.getMonth() + 1).toString().padStart(2, '0');
        let day = date.getDate().toString().padStart(2,'0');
        let hours = date.getHours().toString().padStart(2,'0');
        let minutes = date.getMinutes().toString().padStart(2,'0');
        let seconds = date.getSeconds().toString().padStart(2,'0');
        let dateTimeStr = year+"-"+month+"-"+day+" "+hours+":"+minutes+":"+seconds;
        $("#checkTime").text(dateTimeStr);
    }
</script>
</body>
</html>
